<!DOCTYPE html>
 <html>
 <head>
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
 <% include("/view/console/common/css.html"){}	%>

 <title></title>
 </head>
 <body>
 <div class="zq-form">
 <form name="wnMachine_form"  id="wnMachine_form" class="form-horizontal" style="margin-bottom: 70px;">

  <div class="form-group">
   <label class="control-label col-sm-2 col-xs-2">所属用户</label>
   <div class="col-sm-6 col-xs-6">
    <select class="form-control" id="appUserId"
            name="appUserId" check-type="required">
    </select>
   </div>
  </div>
   <div class="form-group" >
 <label class="col-sm-2 col-xs-2 control-label">车牌号</label>
 <div class="col-sm-6 col-xs-6">
 <input  type="text"  name="licensePlateNumber" id="licensePlateNumber" class="form-control" check-type="required" value='${wnMachine.licensePlateNumber!}' >
 </div>
  </div>
 <div class="form-group" >
 <label class="col-sm-2 col-xs-2 control-label">购入时间</label>
 <div class="col-sm-6 col-xs-6">
 <input  type="text"  name="buyTime" id="buyTime" class="layui-input" check-type="required" value='${wnMachine.buyTime!,"yyyy-MM-dd HH:mm:ss"}' >
 </div>
  </div>
 <div class="form-group">
 <label class="control-label col-sm-2 col-xs-2">型号</label>
 <div class="col-sm-6 col-xs-6">
 	<select class="form-control" id="modelNumber"
 		name="modelNumber" check-type="required">
 </select>
 </div>
 </div>
 <div class="form-group">
 <label class="control-label col-sm-2 col-xs-2">品牌</label>
 <div class="col-sm-6 col-xs-6">
 	<select class="form-control" id="brand"
 		name="brand" check-type="required">
 </select>
 </div>
 </div>
 <div class="form-group">
 <label class="control-label col-sm-2 col-xs-2">所属农场</label>
 <div class="col-sm-6 col-xs-6">
 	<select class="form-control" value="${wnMachine.farmId!}" id="farmId"
 		name="farmId" check-type="required">
 </select>
 </div>
 </div>
  <div class="form-group">
   <label class="col-sm-2 col-xs-2 control-label">挂载机具</label>
   <div class="col-sm-10 col-xs-10">
   <div id="wnMachineToolToolbar" class="btn-group">
    <button type="button" class="btn btn-default" onclick="openAddChild('${ctxPath}/console/wn_machine_tool/addandlink/${wnMachine.id!}')">
     <i class="glyphicon glyphicon-plus"></i>
    </button>
    <button type="button" class="btn btn-default" onclick='wnMachineToolConsoleGrid.delete("id","${ctxPath}/console/wn_machine_tool/delete");'>
     <i class="glyphicon glyphicon-trash"></i>
    </button>
    <button type="button" class="btn btn-default" onclick='linkTool()'>
     关联机具
    </button>
   </div>
     <table id="wnMachineTool" data-toggle="table"
            data-url="${ctxPath}/console/wn_machine_link/tool/json"
            data-pagination="true"
            data-query-params="wnMachineToolLoadParam"
            method="post"
            data-side-pagination="server"
            data-show-refresh="true"
            data-show-toggle="true"
            data-pagination-loop="false"
            data-show-columns="true"
            data-toolbar="#wnMachineToolToolbar">
      <thead>
      <tr>
       <th data-checkbox="true"></th>
       <th data-field='id' data-visible='false'>ID</th>
       <th data-sortable='false' data-field='name'>机具名称</th>
       <th data-sortable='false' data-field='toolNumber'>机具编码</th>
       <th data-sortable='false' data-field='buyTime'  data-formatter="consoleTableDateFormat">购入时间</th>
       <th data-sortable='false' data-field='brand'>品牌</th>
       <th data-sortable='false' data-field='breadth'>幅宽</th>
       <th data-sortable='false' data-field='type'>机具类型</th>
       <th data-sortable='false' data-field='farmName'>所属农场</th>
       <th data-field='id' data-formatter='wnMachineToolTableOperate'>操作</th>

      </tr>
      </thead>
     </table>
   </div>
  </div>
  <div class="form-group" >
  <label class="col-sm-2 col-xs-2 control-label">挂载定位中终端</label>
  <div class="col-sm-10 col-xs-10">
   <div id="wnMachineDeviceImeiToolbar" class="btn-group">
    <button type="button" class="btn btn-default" onclick="openAddChild('${ctxPath}/console/wn_machine_device_imei/addandlink/${wnMachine.id!}');">
     <i class="glyphicon glyphicon-plus"></i>
    </button>
    <button type="button" class="btn btn-default" onclick='wnMachineDeviceImeiConsoleGrid.delete("id","${ctxPath}/console/wn_machine_device_imei/delete");'>
     <i class="glyphicon glyphicon-trash"></i>
    </button>
    <button type="button" class="btn btn-default" onclick='linkGt06Device()'>
     关联设备
    </button>
   </div>
     <table id="wnMachineDeviceImei" data-toggle="table"
            data-url="${ctxPath}/console/wn_machine_link/gt06/json"
            data-pagination="true"
            data-query-params="wnMachineDeviceImeiLoadParam"
            method="post"
            data-side-pagination="server"
            data-show-refresh="true"
            data-show-toggle="true"
            data-pagination-loop="false"
            data-show-columns="true"
            data-toolbar="#wnMachineDeviceImeiToolbar">
      <thead>
      <tr>
       <th data-checkbox="true"></th>
       <th data-field='id' data-visible='false'>ID</th>
       <th data-sortable='false' data-field='deviceNumber'>设备编号</th>
       <th data-sortable='false' data-field='deviceType'>设备类型</th>
       <th data-sortable='false' data-field='farmName'>所属农场</th>
       <th data-sortable='false' data-field='buyTime' data-formatter="consoleTableDateFormat">购入时间</th>
       <th data-sortable='false' data-field='imei'>imei</th>
       <th data-sortable='false' data-field='simcard'>手机号码</th>
       <th data-sortable='false' data-field='validityPeriod'  data-formatter="consoleTableDateFormat">有效期</th>
       <th data-field='id' data-formatter='wnMachineDeviceImeiTableOperate'>操作</th>

      </tr>
      </thead>
     </table>
  </div>
 </div>
  <div class="form-group" >
   <label class="col-sm-2 col-xs-2 control-label">挂载自动驾驶</label>
   <div class="col-sm-10 col-xs-10">
    <div id="wnMachineDeviceToolbar" class="btn-group">
     <button type="button" class="btn btn-default" onclick=" openAddChild('${ctxPath}/console/wn_machine_device/addandlink/${wnMachine.id!}')">
      <i class="glyphicon glyphicon-plus"></i>
     </button>
     <button type="button" class="btn btn-default" onclick='wnMachineDeviceConsoleGrid.delete("id","${ctxPath}/console/wn_machine_device/delete");'>
      <i class="glyphicon glyphicon-trash"></i>
     </button>
     <button type="button" class="btn btn-default" onclick='linkAuto()'>
      关联自动驾驶
     </button>
    </div>
      <table id="wnMachineDevice" data-toggle="table"
             data-url="${ctxPath}/console/wn_machine_link/auto/json"
             data-pagination="true"
             data-query-params="wnMachineDeviceLoadParam"
             method="post"
             data-side-pagination="server"
             data-show-refresh="true"
             data-show-toggle="true"
             data-pagination-loop="false"
             data-show-columns="true"
             data-toolbar="#wnMachineDeviceToolbar">
       <thead>
       <tr>
        <th data-checkbox="true"></th>
        <th data-field='id' data-visible='false'>ID</th>
        <th data-sortable='false' data-field='deviceNumber'>设备号</th>
        <th data-sortable='false' data-field='deviceType'>设备类型</th>
        <th data-sortable='false' data-field='farmName'>所属农场</th>
        <th data-field='id' data-formatter='wnMachineDeviceTableOperate'>操作</th>
       </tr>
       </thead>
      </table>
   </div>
  </div>
   <input type='hidden' name='id' id='id' value='${wnMachine.id!}'><input type='hidden' name='common_token' id='common_token' value='${common_token!}'>
 </form>
  <nav class="navbar navbar-default navbar-fixed-bottom" style="text-align: right">
    <a href="#" class="btn btn-success" style="margin:10px"  onclick='saveZqForm()'>保存 </a>
  </nav>
 </div>
 <% include("/view/console/common/js.html"){} 	%>
 <script>
function openAddChild(url) {
    if($("#id").val()==''){
        layer.alert("请先保存农机基本信息");
    }else{
        consoleOpenWindow('openChild',url,'新增');
    }

}

     layui.use(['layer','laydate'], function(){
       var laydate= layui.laydate;
         //常规用法
         laydate.render({
             elem: '#buyTime'
         });
     });
     $(function($) {
      /*开启表单验证*/
         $("#wnMachine_form").validation();
         componentSelectInit(
             {
                 ctxPath:'',
                 tableName:"sys_dictionary",
                 showValueField:"name",
                 valueField:"value",
                 selectId:"modelNumber"  ,
                 where:" where code ='machine_midel_number' "
             }
             ,function(){
                 $("#modelNumber").val('${wnMachine.modelNumber!}');
             });

      componentSelectInit(
              {
               ctxPath:'',
               tableName:"wn_app_user",
               showValueField:"nick_name",
               valueField:"id",
               selectId:"appUserId"  ,
               where:" where is_del ='0' and user_type = '2' "
              }
              ,function(){
               $("#appUserId").val('${appUserId!}');
              });
         componentSelectInit(
             {
                 ctxPath:'',
                 tableName:"sys_dictionary",
                 showValueField:"name",
                 valueField:"value",
                 selectId:"brand"  ,
                 where:" where code ='machine_brand' "
             }
             ,function(){
                 $("#brand").val('${wnMachine.brand!}');
             });
         componentSelectInit(
             {
                 ctxPath:'',
                 tableName:"wn_farm",
                 showValueField:"name",
                 valueField:"id",
                 selectId:"farmId"  ,
                 where:""
             }
             ,function(){
                 $("#farmId").val("${wnMachine.farmId!}");
                 $("#wnMachineDevice").bootstrapTable("refresh");
                 $("#wnMachineDeviceImei").bootstrapTable("refresh");
                 $("#wnMachineTool").bootstrapTable("refresh");
             });

     });
     /*保存*/
     function saveZqForm(){
         if ($("#wnMachine_form").valid() == false) {
             return false;
         }
         var formObject=new Object();
         formObject.licensePlateNumber=$('#licensePlateNumber').val()==''?null:$('#licensePlateNumber').val();
         formObject.buyTime=$('#buyTime').val()==''?null:$('#buyTime').val();
         formObject.modelNumber=$('#modelNumber').val()==''?null:$('#modelNumber').val();
         formObject.brand=$('#brand').val()==''?null:$('#brand').val();
         formObject.farmId=$('#farmId').val()==''?null:$('#farmId').val();
         formObject.id=$('#id').val()==''?null:$('#id').val();

         var formObjectJson = JSON.stringify(formObject);
         zqPost("/console/wn_machine/save",
             {
                 formObjectJson :formObjectJson,
              appUserId:$("#appUserId").val(),
                 common_token :$("#common_token").val()
             }, function(data) {
                 layer.alert(data.message, {skin: 'layui-layer-molv',closeBtn: 0 }, function(){
                     parent.$("#wnMachine").bootstrapTable("refresh");
                   window.location.href="/console/wn_machine/edit?id="+data.data;
                 });

             });
     }
     function linkGt06Device() {
         if($("#id").val()==''){
             layer.alert("请先保存农机基本信息");
         }else{
             consoleOpenWindow('openChoose',"/console/wn_machine_link/select/page?farmId="+$("#farmId").attr("value")+"&machineId=${wnMachine.id!}",'选择农机关联项');
         }


     }
     function linkTool() {
         linkGt06Device();
     }
     function linkAuto() {
         linkGt06Device();
     }
 </script>
 <script type='text/javascript' src='/view/console/wnMachine/wnMachineForm.js'></script>
 <script type='text/javascript' src='/view/console/wnMachineDevice/wnMachineDeviceTableLink.js'></script>
 <script type='text/javascript' src='/view/console/wnMachineDeviceImei/wnMachineDeviceImeiTableLink.js'></script>
 <script type='text/javascript' src='/view/console/wnMachineTool/wnMachineToolTableLink.js'></script>
 </body>
